package com.yckj.ytracker.api.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Properties;

/**
 * @author liuwei
 * @version 2017/10/17 上午11:21
 * @description
 * @see
 * @since 1.0
 */
public class Config {
    private static final Logger LOGGER = LoggerFactory.getLogger(Config.class);

    private static Global global = Global.getInstance();

    public static void init(Properties properties) {
        if (properties == null || properties.size() == 0) {
            LOGGER.error("properties is null");
            return;
        }
        try {
            String sample = properties.getProperty("sample");
            String closed = properties.getProperty("closed");
            String limit = properties.getProperty("limit");
            global.setSample((sample == null || sample.isEmpty()) ? 1 : Integer.valueOf(sample));
            global.setClosed((closed == null || closed.isEmpty()) ? false : Boolean.valueOf(closed));
            global.setLimit((limit == null || limit.isEmpty()) ? 100 : Integer.valueOf(limit));
        } catch (Exception e) {
            LOGGER.error("config init error:{}", e);
        }

    }
}
